<template>
	<view v-if="!readonly">
		<click-input :value="_value" index="name" @click="showOrgPicker" :disabled="readonly"
			:placeholder="props.formProps.placeholder || $t('webAuto.selectPersonnel')" pre-icon="personadd">
			<view style="flex: 1; display: flex; align-items: center;" v-for="user in _value || []" :key="user.id">
				<avatar :name="user.name" :src="user.avatar" :size="25" :showName="false" />
				<text style="margin-left: 5px;">{{user.name}}</text>
			</view>
		</click-input>
		<org-picker ref="orgPicker" :position="position" :multiple="props.formProps.multiple" type="user" :height="props.height"
			:selected="_value" @ok="selectOk"></org-picker>
	</view>
	<view v-else>
		<view class="w-form-input-rv" style="flex: 1; display: flex; align-items: center;" v-for="user in _value || []" :key="user.id">
			<!-- <avatar :name="user.name" :src="user.avatar" :size="25" :showName="false" /> -->
			<text style="margin-left: 0px;line-height:70rpx;">{{user.name}}</text>
		</view>
	</view>
</template>

<script setup>
	import { ref, computed } from 'vue'
	import OrgPicker from '@/components/OrgPicker.vue'
	import Avatar from '@/components/Avatar.vue'
	import ClickInput from '@/components/ClickInput.vue'

	const props = defineProps({
		formProps: {
			type: Object,
			default: () => {
				return {}
			}
		},
		modelValue: Object,
		readonly: Boolean,
		position: {
			type: String,
			default: 'right'
		},
		height:{
			type: Number
		}
	})

	const _value = computed({
		get() {
			return props.modelValue
		},
		set(val) {
			emits('update:modelValue', val)
		}
	})

	const emits = defineEmits(['update:modelValue'])

	const orgPicker = ref()

	function showOrgPicker() {
		if (!props.readonly) {
			orgPicker.value.show()
		}
	}

	function selectOk(val) {
		_value.value = val
	}
</script>

<style>
</style>